package com.woniu.cinema.controller;

import java.util.List;

import com.woniu.cinema.request.DynamicCinemaRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.woniu.common.annotation.Log;
import com.woniu.common.core.controller.BaseController;
import com.woniu.common.core.domain.AjaxResult;
import com.woniu.common.enums.BusinessType;
import com.woniu.cinema.domain.Cinema;
import com.woniu.cinema.service.CinemaService;
import com.woniu.common.utils.poi.ExcelUtil;
import com.woniu.common.core.page.TableDataInfo;

/**
 * 电影院信息Controller
 * 
 * @author yy
 * @date 2021-04-15
 */
@RestController
@RequestMapping("/cinema/cinema")
public class CinemaController extends BaseController
{
    @Autowired
    private CinemaService cinemaService;

    /**
     * 查询电影院信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Cinema cinema)
    {
        startPage();
        List<Cinema> list = cinemaService.selectCinemaList(cinema);
        return getDataTable(list);
    }

    @RequestMapping("/listAll")
    public List<Cinema> listAllCinema(@RequestParam("id") Long id)
    {
        List<Cinema> list = cinemaService.listAll(id);
        return list;
    }

    @GetMapping("/list/dynamic")
    public TableDataInfo selectCinemaListByDynamicFields(DynamicCinemaRequest request)
    {
        startPage();
        List<Cinema> list = cinemaService.selectCinemaListByDynamicFields(request);
        return getDataTable(list);
    }
    /**
     * 导出电影院信息列表
     */
    @Log(title = "电影院信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Cinema cinema)
    {
        List<Cinema> list = cinemaService.selectCinemaList(cinema);
        ExcelUtil<Cinema> util = new ExcelUtil<Cinema>(Cinema.class);
        return util.exportExcel(list, "cinema");
    }

    /**
     * 获取电影院信息详细信息
     */
    @GetMapping(value = "/{cinemaId}")
    public AjaxResult getInfo(@PathVariable("cinemaId") Long cinemaId)
    {
        return AjaxResult.success(cinemaService.selectCinemaById(cinemaId));
    }

    /**
     * 新增电影院信息
     */
    @Log(title = "电影院信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Cinema cinema)
    {
        return toAjax(cinemaService.insertCinema(cinema));
    }

    /**
     * 修改电影院信息
     */
    @Log(title = "电影院信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Cinema cinema)
    {
        return toAjax(cinemaService.updateCinema(cinema));
    }

    /**
     * 删除电影院信息
     */
    @Log(title = "电影院信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cinemaIds}")
    public AjaxResult remove(@PathVariable Long[] cinemaIds)
    {
        return toAjax(cinemaService.deleteCinemaByIds(cinemaIds));
    }
}
